The probability distribution function for a histogram consists of a set of bins which measure the probability of an event falling into a given range of a continuous variable x. A probability distribution function is defined by the following struct, which actually stores the cumulative probability distribution function. This is the natural quantity for generating samples via the inverse transform method, because there is a one-to-one mapping between the cumulative probability distribution and the range [0,1]. It can be shown that by taking a uniform random number in this range and finding its corresponding coordinate in the cumulative probability distribution we obtain samples with the desired probability distribution.
size_t n
double * range
double * sum
The following functions allow you to create a gsl_histogram_pdf
struct which represents this probability distribution and generate
random samples from it.
gsl_histogram_pdf
struct. If insufficient memory is available a
null pointer is returned and the error handler is invoked with an error
code of GSL_ENOMEM
.
GSL_EDOM
because a probability distribution cannot contain
negative values.
s = range[i] + delta * (range[i+1] - range[i])
where i is the index which satisfies sum[i] <= r < sum[i+1] and delta is (r - sum[i])/(sum[i+1] - sum[i]).